Andreas Karlsson
Contact: andreas.a.karlsson@ki.se
Creating a file called myFile.R
## Smoking, Alcohol and (O)esophageal Cancer fit <- glm(cbind(ncases, ncontrols) ~ agegp + tobgp * alcgp, data = esoph, family = binomial())
We create a repository…
git init
Initialized empty Git repository in /home/andkar/src/ki/Presentations/git/.git/
…and stage our file
git add myFile.R
We check what's going on…
git status
On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: myFile.R
…and commit our staged changes
git commit -m "Simple model of esophagel cancer"
[master b90f403] Simple model of esophagel cancer 1 file changed, 3 insertions(+)
Adding a few lines of code to our file
## The results from the logistic regression summary(fit)
What has changed since last commit?
git diff
diff --git a/myFile.R b/myFile.R
index c388f49..4425392 100644
--- a/myFile.R
+++ b/myFile.R
@@ -1,3 +1,5 @@
## Smoking, Alcohol and (O)esophageal Cancer
fit <- glm(cbind(ncases, ncontrols) ~ agegp + tobgp * alcgp, data = esoph,
family = binomial())
+ ## The results from the logistic regression
+ summary(fit)
We stage & commit those changes
git commit myFile.R -m "Summarise regression results"
[master 1110cbb] Summarise regression results 1 file changed, 2 insertions(+)
We have look at the commit history
git log
commit 1110cbbdfa5feb06d3942789a0e535cb7fe0143a
Author: andreasakarlsson <andreas.a.karlsson@gmail.com>
Date: Wed Feb 10 16:01:38 2016 +0100
Summarise regression results
commit b90f403615d50e4bcfdf8f87b890b32c2262a362
Author: andreasakarlsson <andreas.a.karlsson@gmail.com>
Date: Wed Feb 10 15:58:28 2016 +0100
Simple model of esophagel cancer
We decide to go back to previous version
git checkout b90f4
We look at the commit message and diff
git show
commit b90f403615d50e4bcfdf8f87b890b32c2262a362
Author: andreasakarlsson <andreas.a.karlsson@gmail.com>
Date: Wed Feb 10 15:58:28 2016 +0100
Simple model of esophagel cancer
diff --git a/myFile.R b/myFile.R
index e69de29..c388f49 100644
--- a/myFile.R
+++ b/myFile.R
@@ -0,0 +1,3 @@
+## Smoking, Alcohol and (O)esophageal Cancer
+ fit <- glm(cbind(ncases, ncontrols) ~ agegp + tobgp * alcgp, data = esoph,
+ family = binomial())
| Command | Scope | Common use cases |
|---|---|---|
| git checkout | Commit-level | Switch between branches or inspect old snapshots |
| git checkout | File-level | Discard changes in the working directory |
| git reset | Commit-level | Discard commits in a private branch or throw away uncommited changes |
| git reset | File-level | Unstage a file |
| git revert | Commit-level | Undo commits in a public branch |
| git revert | File-level | (N/A) |
*.aux or *.toc**/log/!myFile.RCreate an annotated tag
git tag -a v1.4 -m "my version 1.4"
See data for a specific tag
git show v1.4
Creates a local version of your remote repository
git clone https://github.com/my_user/my_repository.git
Send local changes to your remote repository
git push
Download changes locally from your remote repository
git pull
Acknowledgements: Alexander Ploner, Henric Winell & Robert Karlsson